home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 4 / MacMania 4.toast / / Tools&Utilities / MathPad 2.4 / Documentation / 3D Plotting next >
Text File  |  1996-03-26  |  3KB  |  42 lines

  1. -- MathPad can display a "3D" projection of surface by using the viewsurf XFun. To try this file, quit MathPad, move the Xfun file "viewsurf" into MathPad's folder and relaunch.
  2.  
  3. -- The surface is specified by a 2D array of z values. The 2D array represents z samples spaced uniformly in x and y. To sample a function over some arbitrary range of x and y values, you can scale array index values to generate the desired x and y values.
  4.  
  5. -- surface function
  6.  z(x,y) = sin(sqrt(x^2+y^2))/sqrt(x^2+y^2)
  7.  
  8.  n = 3*pi
  9.  xmin=-n;  xmax=n    -- desired range of x and y values
  10.  ymin=-n;  ymax=n
  11.  nx=40;    ny=40     -- desired resolution
  12.  
  13. -- sample the function z(x,y) on an evenly spaced grid
  14.  mapx(i) = (i-1)*(xmax-xmin)/(nx-1) + xmin
  15.  mapy(i) = (i-1)*(ymax-ymin)/(ny-1) + ymin
  16.  zgrid[ix,iy] = z(mapx(ix),mapy(iy)) dim[nx,ny]
  17.  
  18. -- Display a 3D projection of the surface
  19.  viewsurf(zgrid,off):
  20.  
  21. --------- View angle
  22. -- The SURFACE window scrollbars can be used to change the view angles. The vertical bar controls the view elevation. The horizontal controls the view azimuth. The direction of the controls corresponds moving the back corner of the surface.
  23.  
  24. --------- Scaling
  25. -- The xy scale is adjusted to fill the window width. The z scale can be controlled by variables "Zmin" and "Zmax". If Zmin and/or Zmax are not specified they will autorange. The base of the surface is at Zmin. Values below Zmin are clipped and displayed as Zmin. Missing data is also displayed as Zmin. Zmax is used for scaling but the surface is not clipped at Zmax.
  26.  
  27.   Zmin=-.2; Zmax=1
  28.  
  29. --------- Click info
  30. -- When the mouse is clicked on a surface grid point, the corresponding z value is shown in an info line at the bottom of the plot. 
  31.  
  32. --------- Printing
  33. -- The viewsurf() function is primarily intended as an interactive way to view a surface. However, the surface view can be copied to the main plot window by setting the 2nd parameter "plotflag" on. The surface is scaled to fit the plot window size at the time of evaluation. If the plot window is re-sized it may distort the projection. You can reevaluate the surface to restore correct scaling. To prevent distortion on printout you should use the zoom box and evaluate the surface with the plot window set to the printer aspect ratio.
  34.  
  35. -------- Comparing image and viewsurf()
  36. -- Note that image and viewsurf() are alternate ways to display the same data.
  37.  
  38.  Xmin=xmin; Xmax=xmax;  Ymin=ymin; Ymax=ymax
  39.  image zgrid
  40.  
  41. -- The viewsurf() display works best for seeing shapes of smooth surfaces. The image command is better for picking out sharp features.
  42.